# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 上午9:41
# @Author  : wb
# @Email   : wb@163.com
# @File    : task_page
# @Software: PyCharm

from time import sleep
from pages.wb_base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

class TaskPage(BasePage):
    url = '/crm'
    # 定位器
    # 获取统计按钮元素
    count_locator = (By.CSS_SELECTOR, 'body > div.container > div:nth-child(1) > ul > li:nth-child(2) > a')
    # '获取新建任务按钮元素
    new_task_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > div > a')
    # 勾选第一条任务
    choose_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    # 删除任务
    delete_locator = (By.ID, 'delete')
    # 获取末页按钮元素
    last_page_locator = (By.LINK_TEXT, '末页')
    # 获取修改按钮元素
    modify_locator = (By.LINK_TEXT, '修改')
    # 获取第一个下拉框元素
    first_select_locator = (By.CSS_SELECTOR, '#field')
    # 获取第三个输入框元素
    search_box_locator = (By.CSS_SELECTOR, '#search')
    # 获取搜索按钮元素
    search_locator = (By.CSS_SELECTOR, '#dosearch')

    # 浏览器操作
    def click_count(self):
        # 点击统计
        self.driver.find_element(*self.count_locator).click()
    def click_new_task(self):
        # 新建任务
        self.driver.find_element(*self.new_task_locator).click()
    def click_choose_first_task(self):
        # 勾选任务
        self.driver.find_element(*self.choose_locator).click()
    def click_delete(self):
        # 点击删除
        self.driver.find_element(*self.delete_locator).click()
        sleep(2)
    def alert_accept(self):
        # 确认警告框
        self.driver.switch_to.alert.accept()
        sleep(3)
    def click_last_page(self):
        # 点击末页
        self.driver.find_element(*self.last_page_locator).click()
    sleep(3)
    def click_modify(self):
        # 点击修改
        self.driver.find_element(*self.modify_locator).click()
    def click_first_select(self):
        # 选择点击第一个下拉选项
        first_select = Select
        first_select_element = self.driver.find_element(*self.first_select_locator)
        first_select_option = Select(first_select_element)
        first_select_option.select_by_index(0)
    def input_search_content(self,search_content):
        # 输入搜索内容
        self.driver.find_element(*self.search_box_locator).send_keys(search_content)
    def click_search(self):
        # 点击搜索
        self.driver.find_element(*self.search_locator).click()
        self.driver.switch_to.alert.accept()
